import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_give/common_ui/dialog/parent_dialog.dart';

/// 弹窗方法
/// 格式-取消-确定
/// ParentDialog - 在parent_dialog.dart 中
class DialogFactory {
  static DialogFactory instance = DialogFactory();

  ///[touchOutsideDismiss]       是否可以点击空白处消失
  ///[backgroundColor]           弹窗外部区域背景色
  ///[borderRadius]              弹窗圆角
  ///[width]                     宽度
  ///[height]                    高度
  ///[margin]                    外边距
  ///[padding]                   内边距
  ///[outsideOnTap]              弹窗外部区域点击事件
  ///[dismissClick]              底部透明消失按钮事件
  ///[showTransparenceButton]    是否显示底部透明消失按钮
  ///[touchOutsideCloseKeyboard] 是否点击空白区域关闭软键盘
  ///[child]                     弹窗子布局
  Future showParentDialog(
      {required BuildContext context,
      bool? touchOutsideDismiss,
      Color? backgroundColor,
      double? borderRadius,
      double? width,
      double? height,
      EdgeInsetsGeometry? margin,
      EdgeInsetsGeometry? padding,
      GestureTapCallback? outsideOnTap,
      GestureTapCallback? dismissClick,
      bool? showTransparenceButton,
      bool? touchOutsideCloseKeyboard,
      Color? bodyBgColor,
      required Widget child}) {
    return showDialog(
        context: context,
        builder: (context) {
          return ParentDialog(
              bodyBgColor: bodyBgColor,
              touchOutsideDismiss: touchOutsideDismiss,
              touchOutsideCloseKeyboard: touchOutsideCloseKeyboard,
              outsideBackgroundColor: backgroundColor,
              borderRadius: borderRadius,
              width: width,
              height: height,
              margin: margin,
              padding: padding,
              outsideOnTap: outsideOnTap,
              childWidget: child,
              dismissClick: dismissClick,
              showTransparenceButton: showTransparenceButton);
        });
  }

  ///检测新版本弹窗
  Future showNeedUpdateDialog(
      {required BuildContext context,
      GestureTapCallback? dismissClick,
      GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "检测到新版本，是否下载更新？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 退出登录
  Future showNeedLogoutDialog(
      {required BuildContext context,
      GestureTapCallback? dismissClick,
      GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定需要退出登陆吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 格式化SD卡
  Future showSDformattingDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定要格式化SD卡吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 注销账号
  Future showNeedCloseuserDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定注销账号吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 设备列表删除
  Future showNeedeqListDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定要删除设备吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 应用数据
  Future showNeedUsedataDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定清除应用数据吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 删除设备好友分享
  Future showNeedsharedataDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定删除好友分享设备吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 关闭设备弹窗 - 黑夜模式下会巡航
  Future showNeedeqcloseDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定要关闭设备吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }

  // 移除共享设备
  Future showEqremoveshareDialog(
      {required BuildContext context,
        GestureTapCallback? dismissClick,
        GestureTapCallback? confirmClick}) async {
    showParentDialog(
        context: context,
        child: TipsCommonDialog(
          title: "确定要移除该设备吗？",
          dialogContentType: DialogContentType.Normal,
          dialogButtonType: DialogButtonType.DoubleButton,
          leftOnTap: () {
            Navigator.pop(context);
            dismissClick?.call();
          },
          rightOnTap: () {
            Navigator.pop(context);
            confirmClick?.call();
          },
        ),
        touchOutsideDismiss: false);
  }


}
